<?php 
 include_once dirname(__FILE__)."/config.php";
 class depot_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_code_depot;
		 protected $_code_unite;
		 protected $_date_depot;
		 protected $_observation;
		 public function get_name_table(){ return "depot";}
		 public function get_name_code_depot(){ return "code_depot";}
		 public function get_name_code_unite(){ return "code_unite";}
		 public function get_name_date_depot(){ return "date_depot";}
		 public function get_name_observation(){ return "observation";}
		 public function set_code_depot($parametre){  $this->_code_depot=$parametre;}	
		 public function set_code_unite($parametre){  $this->_code_unite=$parametre;}	
		 public function set_date_depot($parametre){  $this->_date_depot=$parametre;}	
		 public function set_observation($parametre){  $this->_observation=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_code_depot(){ return $this->_code_depot;}
		 public function get_code_unite(){ return $this->_code_unite;}
		 public function get_date_depot(){ return $this->_date_depot;}
		 public function get_observation(){ return $this->_observation;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 depot(
			code_unite,
			date_depot,
			observation)
 VALUES(
			'".$this->_code_unite."',
			'".$this->_date_depot."',
			'".$this->_observation."')";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_code_unite)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_unite='".$this->_code_unite."'";
}
if(!empty($this->_date_depot)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
date_depot='".$this->_date_depot."'";
}
if(!empty($this->_observation)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
observation='".$this->_observation."'";
}
$sql="UPDATE 
depot SET 
 ".$sql."
								WHERE code_depot ='".$this->_code_depot."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
depot 
 
									WHERE code_depot ='".$this->_code_depot."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
depot ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		code_depot,
		code_unite,
		date_depot,
		observation
 FROM 
 depot";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_code_depot=$row->code_depot;
		$this->_code_unite=$row->code_unite;
		$this->_date_depot=$row->date_depot;
		$this->_observation=$row->observation;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>